/*
 * @Author: jiutian
 * @Date: 2023-02-03 19:53:30
 * @LastEditTime: 2023-02-03 20:06:31
 * @LastEditors:
 */
const multer = require("multer");
const path = require("path");
const fs = require("fs");
const chalk = require("chalk");

// 公共的方法暴露
let commonUploadPic = function (endPath) {
  return multer({
    storage: multer.diskStorage({
      destination: (req, file, cb) => {
        let coverPath = path.join(__dirname, "../blogServe/" + endPath);
        cb(null, coverPath);
      },
      filename: (req, file, cb) => {
        file.originalname = Buffer.from(
          Date.now() + "_" + file.originalname,
          "latin1"
          // "utf8"
        ).toString("utf8");
        file.resetName = file.originalname;
        cb(null, file.resetName);
      },
    }),
  });
};

module.exports = {
  commonUploadPic,
};
